<%-- 
    Document   : index
    Created on : Apr 18, 2012, 3:21:04 PM
    Author     : Winzelric
--%>

<%@page import="weka.core.Instances"%>
<%@page import="utility.FileReader"%>
<%@page import="java.io.DataInputStream"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.io.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name       : Office Memo  
Description: A two-column, fixed-width design with dark color scheme.
Version    : 1.0
Released   : 20120401

-->
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Office Memo by Free CSS Templates</title>
    <link href="http://fonts.googleapis.com/css?family=Arvo" rel="stylesheet" type="text/css" />
    <link href="http://fonts.googleapis.com/css?family=Coda:400,800" rel="stylesheet" type="text/css" />
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    <script type="text/javascript" src="index.js"></script>
  </head>
  <body>
    <%
      String contentType = request.getContentType();
      //here we are checking the content type is not equal to Null and
      String filename = "";
      if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
        DataInputStream in = new DataInputStream(request.getInputStream());
        //we are taking the length of Content type data
        int formDataLength = request.getContentLength();
        byte dataBytes[] = new byte[formDataLength];
        int byteRead = 0;
        int totalBytesRead = 0;
        //this loop converting the uploaded file into byte code
        while (totalBytesRead < formDataLength) {
          byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
          totalBytesRead += byteRead;
        }
        String file = new String(dataBytes);
        //for saving the file name
        String saveFile = file.substring(file.indexOf("filename=\"") + 10);
        saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
        saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\""));
        int lastIndex = contentType.lastIndexOf("=");

        String boundary = contentType.substring(lastIndex + 1, contentType.length());
        int pos;
        //extracting the index of file 
        pos = file.indexOf("filename=\"");
        pos = file.indexOf("\n", pos) + 1;
        pos = file.indexOf("\n", pos) + 1;
        pos = file.indexOf("\n", pos) + 1;
        int boundaryLocation = file.indexOf(boundary, pos) - 4;
        int startPos = ((file.substring(0, pos)).getBytes()).length;
        int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
        // creating a new file with the same name and writing the 
        out.println(saveFile);
        FileOutputStream fileOut = new FileOutputStream(saveFile);
        fileOut.write(dataBytes, startPos, (endPos - startPos));
        fileOut.flush();
        fileOut.close();
    %><Br><table border="2"><tr><td><b>You have successfully
              upload the file by the name of:</b>
            <% out.println(saveFile);%></td></tr></table> <%
                filename = saveFile;
                Instances data = FileReader.readFile(filename);
                session.setAttribute("filename", filename);
                session.setAttribute("dataset", data);
                data = (Instances)session.getAttribute("dataset");
              }

            %>
      <div id="menu-wrapper">
        <div id="menu">
          <ul>
            <li class="current_page_item"><a href="index.jsp">Preprocessing</a></li>
            <li><a href="classification.jsp">Classification</a></li>
          </ul>
        </div>
        <!-- end #menu -->
      </div>
      <div id="header-wrapper">
        <div id="header">
          <div class ="logo">
            <a><img src="Images/widi.png" alt="" /></a>
          </div>
        </div>
      </div>

      <div id="wrapper">
        <!-- end #header -->
        <div id="page">
          <div id="page-bgtop">
            <div id="page-bgbtm">
              <div id="content">
                <form action="go.jsp" method="get">
                    <h2>Attribut</h2>
                    <div class ="button">
                    <button type="button" onclick="markAll()">Mark All</button>
                    <button type="button" onclick="unmarkAll()">Unmark</button>
                    <button type="button" onclick="inverseAll()">Inverse</button>
                    </div>
                    <div class ="attribut">
                    <input type="checkbox" id="f1" name="att" value="1" /> F1 <br/>
                    <input type="checkbox" id="f2" name="att" value="2" /> F2 <br/>
                    <input type="checkbox" id="f3" name="att" value="3" /> F3 <br/>
                    <input type="checkbox" id="f4" name="att" value="4" /> F4 <br/>
                    <input type="checkbox" id="f5" name="att" value="5" /> F5 <br/>
                    <input type="checkbox" id="f6" name="att" value="6" /> F6 <br/>
                    <input type="checkbox" id="f7" name="att" value="7" /> F7 <br/>
                    <input type="checkbox" id="f8" name="att" value="8" /> F8 <br/>
                    </div>
                    <div class ="attribut">
                    <input type="checkbox" id="f9" name="att" value="9" /> F9 <br/>
                    <input type="checkbox" id="f10" name="att" value="10" /> F10 <br/>
                    <input type="checkbox" id="f11" name="att" value="11" /> F11 <br/>
                    <input type="checkbox" id="f12" name="att" value="12" /> F12 <br/>
                    <input type="checkbox" id="f13" name="att" value="13" /> F13 <br/>
                    <input type="checkbox" id="f14" name="att" value="14" /> F14 <br/>
                    <input type="checkbox" id="f15" name="att" value="15" /> F15 <br/>
                    </div>
                    <div class ="attribut">
                    <input type="checkbox" id="f16" name="att" value="16" /> F16 <br/>
                    <input type="checkbox" id="f17" name="att" value="17" /> F17 <br/>
                    <input type="checkbox" id="f18" name="att" value="18" /> F18 <br/>
                    <input type="checkbox" id="f19" name="att" value="19" /> F19 <br/>
                    <input type="checkbox" id="f20" name="att" value="20" /> F20 <br/>
                    <input type="checkbox" id="f21" name="att" value="21" /> F21 <br/>
                    <input type="checkbox" id="f22" name="att" value="22" /> F22 <br/>
                    </div>
                    <div class ="button">
                        <input type="submit" value="go"/>
                    </div>
               </form>
              </div>
              <!-- end #content -->
              <div id="sidebar">
                <ul>
                  <li>
                    <div class ="saveload">
                      <form action="index.jsp" enctype="multipart/form-data" method="post">
                        <input type="file" id="datafile" name="datafile" size="40">
                          <input type="submit" value="Load" />
                      </form>
                    </div>
                    <h2>Filter</h2>
                    <form action="filter.jsp" method="get">
                        <td> <input type="radio" name="select" value="search1" /> unsupervised discretize <br/></td>
                        <td> <input type="radio" name="select" value="search2"  /> unsupervised normalize (attribute) <br/></td>
                        <td> <input type="radio" name="select" value="search3"  /> unsupervised replace missing value <br/></td>
                        <td> <input type="radio" name="select" value="search4"  /> supervised Attribute Selection <br/></td>
                        <td> <input type="radio" name="select" value="search5" checked />no filter <br/></td>
                        <td> <input type="submit" value="go"/> </td>
                    </form>

                    
                    <div style="clear: both;">&nbsp;</div>
                  </li>
                  <li>
                    <h2>Keterangan</h2>
                    <p>Widi's Heart adalah suatu aplikasi machine learning sederhana. Aplikasi ini akan mengdiagnosis kondisi jantung berdasarkan nilai atribut-atribut yang dimiliki oleh jantung</p>
                  </li>
                </ul>
              </div>
              <!-- end #sidebar -->
              <div style="clear: both;">&nbsp;</div>
            </div>
          </div>
        </div>
        <!-- end #sidebar -->
        <div style="clear: both;">&nbsp;</div>
      </div>
      </div>
      </div>
      <!-- end #page -->
      </div>
      <%
        
      %>
      <div id="footer">
        <p>&copy; 2012 Sitename.com. | Photos by <a href="http://fotogrph.com/">Fotogrph</a> | Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
      </div>
      <!-- end #footer -->
  </body>
</html>

